<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('消费列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 100px">品牌名称：</label>
                            <select name="manuNum" >
                                <option value="">选择品牌</option>
                                <option th:each="m:${manufacturer}" th:text="${m.MANU_NAME}" th:value="${m.MANU_NUM}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">商户编号：</label>
                            <input type="text" name="merNo"/>
                        </li>
                        <li>
                            <label style="width: 100px;">上游商户编号：</label>
                            <input type="text" name="ldMerno"/>
                        </li>
                        <li>
                            <label style="width: 100px;">交易状态：</label>
                            <select name="status">
                                <option value="">所有</option>
                                <option value="-1">撤销</option>
                                <option value="-2">冲正</option>
                                <option value="0">成功</option>
                                <option value="2">失败</option>
                                <option value="1">补录</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">交易类型：</label>
                            <select name="msgtype">
                                <option value="">所有</option>
                                <option value="H007">消费</option>
                                <option value="H014">退货</option>
                                <option value="S007">SIM卡年费</option>
                                <option value="V007">会员交易</option>
                                <option value="C007">手机充值</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">交易卡号：</label>
                            <input type="text" name="pan"/>
                        </li>
                        <li>
                            <label style="width: 100px;">流水号：</label>
                            <input type="number" name="serial"/>
                        </li>
                        <li>
                            <label style="width: 100px;">交易详细地址：</label>
                            <input type="text" name="addressAll"/>
                        </li>
                        <li>
                            <label style="width: 100px;">结算类型：</label>
                            <select name="settType">
                                <option value="">所有</option>
                                <option value="0">D0</option>
                                <option value="1">T1</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">云闪付交易：</label>
                            <select name="isysf">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">双免交易：</label>
                            <select name="isdissmis">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">服务编号：</label>
                            <input type="text" name="agentNum"/>
                        </li>
                        <li>
                            <label style="width: 100px;">终端号：</label>
                            <input type="text" name="terno"/>
                        </li>
                        <li>
                            <label style="width: 100px;">SN码：</label>
                            <input type="text" name="sn"/>
                        </li>
                        <li>
                            <label style="width: 100px;">卡类型：</label>
                            <select name="cardtype">
                                <option value="">所有</option>
                                <option value="0">未知</option>
                                <option value="1">借记卡</option>
                                <option value="2">贷记卡</option>
                                <option value="3">预付费卡</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">清算状态：</label>
                            <select name="auState">
                                <option value="">所有</option>
                                <option value="0">未清</option>
                                <option value="1">已清</option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 100px;">扣款类型：</label>
                            <select name="chargeType">
                                <option value="-2">所有</option>
                                <option value="0">流量费</option>
                                <option value="1">服务费</option>
                                <option value="-1">正常消费</option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label style="width: 100px;">交易日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 search-collapse">
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">交易总笔数：</span>
            <span id="counten" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 笔</span>
            <span style="color:blue">]</span>
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">交易商户数：</span>
            <span id="mercount" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 个</span>
            <span style="color:blue">]</span>
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">交易总金额：</span>
            <span id="amount" style="color: red;font-style: initial">0.00</span><span style="color: blue;font-style: initial"> 元</span>
            <span style="color:blue">]</span>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="exportDetailExcel()" shiro:hasPermission="bankExpenditure:bankExpenditure:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary single " onclick="getQianGouDan()" shiro:hasPermission="bankExpenditure:bankExpenditure:getQianGouDan">
                <i class="fa fa-edit"></i> 电签签购单
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table text-nowrap"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('bankExpenditure:bankExpenditure:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bankExpenditure:bankExpenditure:remove')}]];
    var prefix = ctx + "bankExpenditure/bankExpenditure";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            clickToSelect:true,
            firstLoad:false,
            modalName: "消费",
            responseHandler:responseHandler,
            columns: [{
                radio: true
            },
                {
                    field: 'serial',
                    title: '流水号'
                },
                {
                    field: 'merchantInfo.merno',
                    title: '商户编号'
                },
                {
                    field: 'ldMerno',
                    title: '上游商户编号'
                },
                {
                    field: 'merchantInfo.merName',
                    title: '商户名称'
                },
                {
                    field: 'bid',
                    title: '编号代码'
                },
                {
                    field: 'merchantInfo.agentNo',
                    title: '服务商编号'
                },
                {
                    field: 'agentInfo.agentName',
                    title: '服务商名称'
                },
                {
                    field: 'accounts.screenName',
                    title: '结算人'
                },
                {
                    field: 'msgtype',
                    title: '交易类型',
                    formatter: function (value, row, index) {
                        if ("H007" == value) {
                            return '<span style="color:blue;">消费</span>';
                        } else if ("H014" == value) {
                            return '<span style="color:red;">退货</span>';
                        } else if ("S007" == value) {
                            return '<span style="color:blue;">SIM卡年费</span>';
                        } else if ("V007" == value) {
                            return '<span style="color:blue;">会员交易</span>';
                        } else if ("C007" == value) {
                            return '<span style="color:orange;">手机充值</span>';
                        } else {
                            return "未知";
                        }
                    }
                },
                {
                    field: 'isysf',
                    title: '是否云闪付',
                    formatter: function (value, row, index) {
                        if (value == '0') {
                            return '<span style="color:red;">否</span>';
                        } else if (value == '1') {
                            return '<span style="color:green;">是</span>';
                        }
                    }
                },
                {
                    field: 'isdissmis',
                    title: '是否双免',
                    formatter: function (value, row, index) {
                        if (value == '1') {
                            return '<span style="color:green;">是</span>';
                        } else if (value == '0') {
                            return '<span style="color:red;">否</span>';
                        }
                    }
                },
                {
                    field: 'terno',
                    title: '终端号'
                },
                {
                    field: 'localdate',
                    title: '交易日期'
                },
                {
                    field: 'localtime',
                    title: '交易时间'
                },
                {
                    field: 'pan',
                    title: '交易卡号'
                },
                {
                    field: 'amount',
                    title: '交易金额',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    field: 'status',
                    title: '交易状态',
                    formatter: function (value, row, index) {
                        if ("-1" == value) {
                            return '<span style="color:red;">撤销</span>';
                        } else if ("-2" == value) {
                            return '<span style="color:orange;">冲正</span>';
                        } else if ("0" == value) {
                            return '<span style="color:green;">成功</span>';
                        } else if ("2" == value) {
                            return '<span style="color:red;">失败</span>';
                        } else if ("1" == value) {
                            return '<span style="color:orange;">补录</span>';
                        } else {
                            return "未知";
                        }
                    }
                },
                {
                    field: 'cardtype',
                    title: '卡类型',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return '<span style="color:orange;">未知</span>';
                        } else if ("1" == value) {
                            return '<span style="color:green;">借记卡</span>';
                        } else if ("2" == value) {
                            return '<span style="color:red;">贷记卡</span>';
                        } else if ("3" == value) {
                            return '<span style="color:purple;">预付费卡</span>';
                        }
                    }
                },
                {
                    field: 'settType',
                    title: '清算类型',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return '<span style="color:red;">D0</span>';
                        } else if ("1" == value) {
                            return '<span style="color:green;">T1</span>';
                        }
                    }
                },
                {
                    field: 'auState',
                    title: '清算状态',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return '<span style="color:red;">未清算</span>';
                        } else if ("1" == value) {
                            return '<span style="color:green;">已清算</span>';
                        }
                    }
                },
                {
                    field: 'rc',
                    title: '返回码',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'addressAll',
                    title: '交易详细地址',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'simMoney',
                    title: '扣款金额'
                },
                {
                    field: 'chargeType',
                    title: '扣款类型',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return '<span style="color:steelblue;">流量费</span>';
                        } else if ("1" == value) {
                            return '<span style="color:blue;">服务费</span>';
                        }else if ("-1" == value) {
                            return '<span style="color:green;">正常消费</span>';
                        }else{
                            return '<span style="color:red;">未知</span>';
                        }
                    }
                }]
        };
        $.table.init(options);
    });

    /**
     * 导出明细
     * @param
     */
    function exportDetailExcel(){
        $.modal.loading("正在导出数据，请稍后...");
       // var dataParam = {"ordernumber":orderNumber};
        $.post(prefix+"/export", $("#formId").serialize(),function(result) {
            if (result.code == web_status.SUCCESS) {
                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
            } else if (result.code == web_status.WARNING) {
                $.modal.alertWarning(result.msg)
            } else {
                $.modal.alertError(result.msg);
            }
            $.modal.closeLoading();
        });
    }

    function getQianGouDan() {
        var serial = $.table.selectColumns("serial")
        var status = $.table.selectColumns("status")
        var data = "?serial=" + serial + "&status=" + status;
        if ($.common.isEmpty(serial)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        // $.modal.open("查看图片", prefix + '/lookImg/' + merNo, '1200');

        //如果是移动端，就使用自适应大小弹窗
        var width=500;
        var height=$(window).height() - 150;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        var url=prefix + '/getQianGouDan/' + data;
        //$.modal.open("商品详情", url,width, height);
        var btn = ['关闭'];
        var options = {
            title: '查看图片',
            width: width,
            height: height,
            url: url,
            btn: btn,
            yes:function(index){
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function responseHandler(res) {
        $("#counten").text(res.data.COUNTEN);
        $("#amount").text(res.data.AMOUNT);
        $("#mercount").text(res.data.MERCOUNT);
    }
</script>
</body>
</html>